package com.xds.springcloud.controller;
import com.xds.springcloud.entity.CommonResult;
import com.xds.springcloud.entity.Payment;
import com.xds.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-09-11
 */
@RestController
@RequestMapping("/payment")
@Slf4j

public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    @Value("${server.port}")
    private String serverPort;
    @PostMapping("create")
    public CommonResult create( @RequestBody Payment payment){
        boolean save = paymentService.save(payment);
        if (save){
            return new CommonResult(200, "插入成功,serverPort"+serverPort);
        }else {
            return new CommonResult(201, "插入失败");
        }
    }
    @GetMapping("get/{id}")
    public CommonResult get(@PathVariable("id") Long id ){
        Payment payment = paymentService.getById(id);
        log.info("查询结果"+payment);
        if (payment!=null){
            return new CommonResult(200, "查询成功,serverPort"+serverPort,payment);
        }else {
            return new CommonResult(201, "查询不到,id"+id,null);
        }
    }
    @GetMapping("lb")
    public String getPaymentLB() {
        return serverPort;
    }
}

